package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SubTask;
import com.ruoyi.system.service.ISubTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 子任务Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@RestController
@RequestMapping("/task/subTask")
public class SubTaskController extends BaseController
{
    @Autowired
    private ISubTaskService subTaskService;

    /**
     * 查询子任务列表
     */
    @PreAuthorize("@ss.hasPermi('task:subTask:list')")
    @GetMapping("/list")
    public TableDataInfo list(SubTask subTask)
    {
        startPage();
        List<SubTask> list = subTaskService.selectSubTaskList(subTask);
        return getDataTable(list);
    }

    /**
     * 导出子任务列表
     */
    @PreAuthorize("@ss.hasPermi('task:subTask:export')")
    @Log(title = "子任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SubTask subTask)
    {
        List<SubTask> list = subTaskService.selectSubTaskList(subTask);
        ExcelUtil<SubTask> util = new ExcelUtil<SubTask>(SubTask.class);
        util.exportExcel(response, list, "子任务数据");
    }

    /**
     * 获取子任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('task:subTask:query')")
    @GetMapping(value = "/{subTaskId}")
    public AjaxResult getInfo(@PathVariable("subTaskId") Long subTaskId)
    {
        return success(subTaskService.selectSubTaskBySubTaskId(subTaskId));
    }

    /**
     * 新增子任务
     */
    @PreAuthorize("@ss.hasPermi('task:subTask:add')")
    @Log(title = "子任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SubTask subTask)
    {
        return toAjax(subTaskService.insertSubTask(subTask));
    }

    /**
     * 修改子任务
     */
    @PreAuthorize("@ss.hasPermi('task:subTask:edit')")
    @Log(title = "子任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SubTask subTask)
    {
        return toAjax(subTaskService.updateSubTask(subTask));
    }

    /**
     * 删除子任务
     */
    @PreAuthorize("@ss.hasPermi('task:subTask:remove')")
    @Log(title = "子任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{subTaskIds}")
    public AjaxResult remove(@PathVariable Long[] subTaskIds)
    {
        return toAjax(subTaskService.deleteSubTaskBySubTaskIds(subTaskIds));
    }
}
